﻿using Kang.ExtendMethod;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kang.Test.Framework.WPF
{
    public static class Ex
    {

        public static IList<T> GetRandomItems<T>(this IList<T> list, int count)
        {
            if (list == null)
            {
                return default;
            }
            if (list.Count <= 0)
            {
                return default;
            }
            byte[] buffer = Guid.NewGuid().ToByteArray();//将Guid转换为字节数组
            int seed = BitConverter.ToInt32(buffer, 0);
            Random random = new Random(seed);
            var items = new List<T>();
            count.For(i =>
            {
                items.Add(list[random.Next(0, list.Count)]);
            });
            return items;
        }
    }
}
